<template>
	<view>
		<view class="uni-list">
			<view class="uni-list-cell uni-list-cell-pd"  v-for="(item,index) in gateways" :key="index" v-if="item.isVoice!=1">
				<view class="uni-list-cell-db" style="letter-spacing: 2rpx;font-weight: 500;">{{item.deviceName}}</view>
				<view class="button" @click="operate(item.id,0)"><text>开启</text></view>
				<view class="button" @click="operate(item.id,1)"><text>关闭</text></view>
			</view>
		</view>
	</view>
</template>

<script>
	import Api from '@/common/api';
	export default {
		data() {
			return {
				gateways:[],
				orderId:null
			}
		},
		onLoad(options) {
			console.log(options.orderId)
			this.orderId = options.orderId;
			this.getGateways(options.deviceId,options.storeId);
		},
		methods: {
			async operate(gatewayDeviceId,type,orderId){
				let res = await Api.apiCall('post', Api.gateway.operate, {gatewayDeviceId:gatewayDeviceId,type:type,orderId:this.orderId});
				if(res){
					if(res==1){
						uni.showToast({
							icon:'error',
							title:'请先开启包间'
						})
						return;
					}else{
						uni.showToast({
							icon:'success',
							title:'操作成功'
						})
					}
				}
			},
			async getGateways(deviceId,storeId){
				let res = await Api.apiCall('post', Api.gateway.getGateways, {deviceId:deviceId,storeId:storeId});
				if(res){
					this.gateways = res;
					console.log(this.gateways)
				}
			}
		}
	}
</script>

<style>
	.button{
		margin-left: 30rpx;
		background-color: #44a17f;
		width: 100rpx;
		border-radius: 15rpx;
		text-align: center;
		letter-spacing: 2rpx;
		color: #ffffff;
	}
</style>
